package cn.piesat.client.schedule;

import cn.piesat.client.constant.cache.LocalCache;
import cn.piesat.client.model.dto.base.task.DefaultClientRunnerDto;
import cn.piesat.client.model.dto.buiness.QsClientRunnerDto;
import cn.piesat.client.service.RedisSateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.Map;

/**
 * 客户端定时任务
 */
@Configuration
public class StateScheduler {

    @Autowired
    private RedisSateService redisSateService;

    /**
     * 健康监测请求
     * 程序启动开始,每隔5s执行一次
     */
    @Scheduled(fixedRate=5000)
    private void healthInformation(){
        redisSateService.healthInformation();
    }

    /**
     * 更新算法记录状态（目前有算法执行日志,执行流程图）
     * 0s开始每5s
     */
    @Scheduled(cron = "0/5 * * * * ?")
    private void updateRecord(){
        Map<String, ? super DefaultClientRunnerDto> taskRunnerCacheMap = LocalCache.taskRunnerCache;
        for (Map.Entry<String, ? super DefaultClientRunnerDto> entry : taskRunnerCacheMap.entrySet()) {
            redisSateService.recordStatus((QsClientRunnerDto) entry.getValue(),false);
        }
    }
}
